package gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import entidade.Aluno;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Pesquisar extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField fieldMatricula;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Pesquisar dialog = new Pesquisar();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Pesquisar() {
		setModal(true);
		setResizable(false);
		setTitle("Pesquisar");
		setBounds(100, 100, 550, 170);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		JLabel lblPesquisarPorMatricula = new JLabel("Pesquisar por Matricula: ");
		fieldMatricula = new JTextField();
		fieldMatricula.setColumns(10);
		JButton btnPesquisar_1 = new JButton("Pesquisar");
		btnPesquisar_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CRUD_Principal cp = new CRUD_Principal();
				int mat = Integer.parseInt(fieldMatricula.getText());
				String a = "";
				try{
					a = "Nome: " + cp.aluno.get(mat).getNome() + "\n" + "Curso: " + cp.aluno.get(mat).getCurso() + "\n" + "Matricula: " + cp.aluno.get(mat).getMatricula()
						 + "\n" + "Sexo: " + cp.aluno.get(mat).getSexo() + "\n" + "Idade: " + cp.aluno.get(mat).getIdade();
					fieldMatricula.setText("");
					JOptionPane.showMessageDialog(null, a);
			
				
				} catch(IndexOutOfBoundsException e){
					JOptionPane.showMessageDialog(null, "Matricula inexistente");
				
				}
			}
		});
		JButton btnCancelar = new JButton(" Cancelar ");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addComponent(lblPesquisarPorMatricula)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(fieldMatricula, GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
							.addGap(18)
							.addComponent(btnPesquisar_1))
						.addComponent(btnCancelar, Alignment.TRAILING))
					.addContainerGap())
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(36)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblPesquisarPorMatricula)
						.addComponent(fieldMatricula, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnPesquisar_1))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnCancelar)
					.addContainerGap(30, Short.MAX_VALUE))
		);
		contentPanel.setLayout(gl_contentPanel);
	}

}
